using System.Collections;

namespace cuberga.Workflow
{
    public abstract class AbstractPublisher : IPublisher
    {
        private ArrayList _subscribers = new ArrayList();
        private object _state; // = new DefaultState();

        #region ISubject Members

        public void Subscribe(ISubscriber subscriber)
        {
            _subscribers.Add(subscriber);
        }

        public void Unsubscribe(ISubscriber subscriber)
        {
            _subscribers.Remove(subscriber);
        }

        //public IState GetState()
        public object GetState()
        {
            return _state;
        }

        #endregion

        protected void Notify()
        {
            foreach (ISubscriber subscriber in _subscribers)
            {
                subscriber.Update(this);
            }
        }

        // other signatures creates states of different types
        protected void SetState(object state)
        {
            _state = state;
            Notify();
        }
    }
}